import { DeviceManager } from "../network/manager/DeviceManager";
import { AbnormalUtils } from "./AbnormalUtils";
let deviceManager = new DeviceManager();
let abnormalUtils = new AbnormalUtils();
let logManager = my.getRealtimeLogManager();

class OperationUtils {

  static createLog() {
    
  }

  static uploadLog(log) {
    // 对整形转成String
    console.log("---转换前---");
    console.log(JSON.stringify(log));
    // logManager.error("转换前", JSON.stringify(log));
    if (typeof log.typeCode == "number") {
      log.typeCode = ("0000" + log.typeCode.toString(16)).slice(-4).toUpperCase();
    }
    if (typeof log.resultCode == "number") {
      log.resultCode = ("000000" + log.resultCode.toString(16)).slice(-6).toUpperCase();
    }
    console.log("---转换后---");
    console.log(JSON.stringify(log));
    // logManager.error("转换后", JSON.stringify(log));
    deviceManager.uploadOperateRecord(log)
      .then(res => {
        if (res.code == 0) {
          console.log("操作记录上传成功")
        } else if (res.code == 1603) {
          console.log("操作记录上传失败");
          logManager.error(log, "上传日志错误");
        } else {
          console.log("操作记录上传失败 i = ")
          abnormalUtils.addUnuploadLog(log);
        }
      }, err => {
        abnormalUtils.addUnuploadLog(log);
        console.log("操作记录上传异常 i = " + i)
      })
  }
}

export {
  OperationUtils
}